package com.cf.performance.core;

import com.twitter.zipkin.gen.Span;
import lombok.extern.slf4j.Slf4j;

import java.util.Stack;

/**
 * game-server-CallTrack
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/5/16 下午 04:03
 */
@Slf4j
public class CallTrack {


    protected static ThreadLocal<Stack<Span>> spans = new ThreadLocal<Stack<Span>>() {
        @Override
        protected Stack<Span> initialValue() {
            return new Stack();
        }
    };


    public static Span last() {
        Stack<Span> spans = CallTrack.spans.get();
        if (spans.size() == 0)
            return null;
        return spans.peek();
    }

    public static int size() {
        return spans.get().size();
    }

    public static Span pop() {
        Span last = last();
        if (last == null)
            return last;
        return CallTrack.spans.get().pop();
    }

    public static void push(Span span) {
        spans.get().push(span);
    }

}
